#ifndef __BidirectionI_h__
#define __BidirectionI_h__

#include <Bidirection.h>
#include <thread>
#include <mutex>

namespace Demo
{
	struct ClientInfo {
		ClientInfo(const std::string& _ip = "", const std::string& _port = "")
			:mIP(_ip),
			mPort(_port)
		{

		}
		std::string mIP;
		std::string mPort;
	};
	class CallbackReceiverImpl : virtual public CallbackReceiver
	{
	public:

		virtual void callback(::Ice::Int, const Ice::Current&)override;
	};

	class CallbackSenderImpl : virtual public CallbackSender
	{
	public:
		CallbackSenderImpl();

		~CallbackSenderImpl();
	public:
		virtual void addClient(const ::Ice::Identity& ident, const Ice::Current&)override;

		virtual void registerConntionHandler(const ::std::string& clientId, const ::Ice::Current& = ::Ice::Current())override;
	public:
		void notifyClients();

		void removeClient(const std::string& _clientID);
	private:
		void loop();
	private:
		std::map<std::string, CallbackReceiverPrx> m_Clients;
		std::map<std::string, ClientInfo> m_idClientInfoMap;
		std::thread m_WorkThread;
		std::atomic<bool> m_ExitFlag = ATOMIC_VAR_INIT(true);
		std::mutex m_ClientsMutex;
	};
}

#endif
